/**
 * 
 */
package de.midnightdance.server.test;

import java.util.List;

import javax.swing.JOptionPane;
import javax.xml.ws.Endpoint;

import de.midnightdance.model.character.CharacterRequiemVampir;
import de.midnightdance.model.user.RequiemUser;
import de.midnightdance.server.model.RequiemModelPersistance;
import de.midnightdance.server.service.ServiceAdminRequiem;
import de.midnightdance.server.service.ServiceModelRequiem;

/**
 * @author Surfer
 *
 */
public class LauncherServer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LauncherServer launcher = new LauncherServer();
		launcher.startModelServer();
		launcher.addTestUser();
//		launcher.addTestData();
		launcher.startWebServer();
	}

	private void startWebServer(){
		Endpoint endpointModel = Endpoint.publish("http://localhost:8090/WebServiceModelRequiem?wsdl",
                new ServiceModelRequiem());
		Endpoint endpointAdmin = Endpoint.publish("http://localhost:8090/WebServiceAdminRequiem?wsdl",
                new ServiceAdminRequiem());
        JOptionPane.showMessageDialog(null, "Shutdown Server");
        endpointModel.stop();
        endpointAdmin.stop();        
	}
	
	protected void startModelServer(){
		RequiemModelPersistance.getInstance().startServer();	
	}
	
	private void addTestUser() {
		RequiemUser initUser = new RequiemUser();
		initUser.setName("testUser");
		initUser.setPass("test");
		//
		RequiemModelPersistance model = RequiemModelPersistance.getInstance();
		//
		List<RequiemUser> testUser = TestDataProvider.getUsers();
		for (RequiemUser user : testUser) {
			model.saveUser(user, initUser);
		}
	}

	
	protected void addTestData() {
		RequiemUser initUser = new RequiemUser();
		initUser.setName("testUser");
		initUser.setPass("test");
		//
		RequiemModelPersistance model = RequiemModelPersistance.getInstance();
		//
		List<CharacterRequiemVampir> testVampires = TestDataProvider.getVampires();
		for (CharacterRequiemVampir vampire : testVampires) {
			model.saveEntity(vampire, initUser);
		}
	}
}
